<?php

function getSiteSettings($id, $templ=0)
{
	$site['id'] = $katana->Id;
	
	if(THEME_ID > 0)
	{ $and = ' AND id='.THEME_ID; }
	else
	{
		if($templ > 0)
		{ $and = ' AND id='.$templ; }
		else
		{ $and = ' AND site_default=1'; }
	}
	$selection = 'SELECT * FROM '.DB_PERFIX.'themes WHERE site_id='.$id.$and.' LIMIT 1;';
	$result = mysql_query($selection);
	while($row = mysql_fetch_array($result))
	{
		$site['theme_type']			= $row['theme_type'];
		$site['border_site']		= $row['border_site'];
		$site['border_content'] 	= $row['border_content'];
		
		$site['header']				= $row['header']; 
		$site['header_border'] 		= $row['header_border'];
		$site['header_hfb'] 		= $row['header_hfb'];
		$site['header_content'] 	= $row['header_content'];
		
		$site['footer']				= $row['footer'];
		$site['footer_border'] 		= $row['footer_border'];
		$site['footer_hfb'] 		= $row['footer_hfb'];
		$site['footer_content'] 	= $row['footer_content'];
		
		$site['col_left']			= $row['col_left'];
		$site['col_left_border'] 	= $row['col_left_border'];
		$site['col_left_hfb'] 		= $row['col_left_hfb'];
		$site['col_left_content'] 	= $row['col_left_content'];
		
		$site['col_right']			= $row['col_right'];
		$site['col_right_border'] 	= $row['col_right_border'];
		$site['col_right_hfb'] 		= $row['col_right_hfb'];
		$site['col_right_content'] 	= $row['col_right_content'];
		
		$site['hfb_set'] 			= $row['hfb_set'];
		$site['hfb_com_set'] 		= $row['hfb_com_set'];
		
		define('THEME_ID', $row['id']);
		define('DEF_HFB', $site['hfb_set']);
	}
	return $site;
}

function getComponentsList()
{
	$i=0;
	$result = mysql_query('SELECT id, name_l, name_r FROM '.DB_PERFIX.'components ORDER BY name_l ASC;');
	while($row = mysql_fetch_array($result))
	{
		$item[$i]['id'] = $row['id'];
		$item[$i]['name_l'] = $row['name_r'];
		$i++;
	}
	return $item;
}

function getModulesList()
{
	$i=0;
	$result = mysql_query('SELECT id, name_l, name_r FROM '.DB_PERFIX.'modules ORDER BY name_l ASC;');
	while($row = mysql_fetch_array($result))
	{
		$item[$i]['id'] = $row['id'];
		$item[$i]['name_l'] = $row['name_l'];
		$item[$i]['name_r'] = $row['name_r'];
		$i++;
	}
	return $item;
}

function getContentTemplates($site=0, $area=0)
{
	$i=0;
	$where = '';
	if($site > 0)
	{ 
		$where = ' WHERE site_id='.$site.' '; 
		if($area > 0)
		{
			$where .= ' AND site_area='.$area.' '; 
		}
	}
	$result = mysql_query('SELECT id, site_id, site_area, title, access, active FROM '.DB_PERFIX.'content '.$where.' ORDER BY title ASC;');
	while($row = mysql_fetch_array($result))
	{
		$item[$i]['id'] = $row['id'];
		$item[$i]['site_id'] = $row['site_id'];
		$item[$i]['site_area'] = $row['site_area'];
		$item[$i]['title'] = $row['title'];
		$item[$i]['access'] = $row['access'];
		$item[$i]['active'] = $row['active'];
		$i++;
	}
	return $item;
}

function getHTMLList()
{
	$i=0;
	$result = mysql_query('SELECT id, name_l, name_r FROM '.DB_PERFIX.'template_html ORDER BY name_l ASC;');
	while($row = mysql_fetch_array($result))
	{
		$item[$i]['id'] = $row['id'];
		$item[$i]['name_l'] = $row['name_l'];
		$item[$i]['name_r'] = $row['name_r'];
		$i++;
	}
	return $item;
}

function getCountryList()
{
	$select = 'SELECT iso, printable_name FROM '.DB_PERFIX.'country;';
	$result = mysql_query($select);
	if(mysql_num_rows($result) > 0)
	{
		$i = 0;
		while($row = mysql_fetch_array($result))
		{
			$country[$i]['iso'] = $row['iso'];
			$country[$i]['name'] = $row['printable_name'];
			$country[$i]['printable_name'] = $row['printable_name'];
			$i++;
		}
		return $country;
	}
}

function getStatesList()
{
	$select = 'SELECT id, name FROM '.DB_PERFIX.'states;';
	$result = mysql_query($select);
	if(mysql_num_rows($result) > 0)
	{
		$i = 0;
		while($row = mysql_fetch_array($result))
		{
			$states[$i]['id'] = $row['id'];
			$states[$i]['name'] = $row['name'];
			$i++;
		}
		return $states;
	}
}
?>